                                                               /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.hugo.senai.view;

import br.com.hugo.senai.testes.PainelTrasnparente;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.Timer;
import javax.swing.UIManager;

/**
 *
 * @author Hugo
 */
public class Loading extends javax.swing.JFrame {

    /**
     * Creates new form Loading
     */
    int valor = 0;

    public class loading implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            barraProgresso.setValue(valor);
            
            porcentagem.setText(valor+"%");

            if (barraProgresso.getValue() < 20) {
                barraProgresso.setString("Ligando para o banco de dados...");
            } else if (barraProgresso.getValue() < 40) {
                barraProgresso.setString("Instanciando os objetos....");
            } else if (barraProgresso.getValue() < 60) {
                barraProgresso.setString("Arrumando a mesa de trabalho...");
            } else if (barraProgresso.getValue() < 80) {
                barraProgresso.setString("Tirando uma soneca......mentira.");
            } else if (barraProgresso.getValue() < 100) {
                barraProgresso.setString("Pronto. Vamos começar....");
            } else if (barraProgresso.getValue() == 100) {
                dispose();
                new Login().setVisible(true);
                timer.stop();
            }
            
            
            valor += 1;
        }

    }

    Timer timer = new Timer(50, new loading());
//    public static int x;
//    public static int y;
//    public static int width;
//    public static int height;

    public Loading() throws AWTException {

        ///Carregando as propriedades da barra
        // UIManager.put("ProgressBar.foreground", Color.decode("#FF6666"));
        //UIManager.getLookAndFeelDefaults().put("nimbusOrange", (Color.decode("#FF6666")));
        //instancia o painel  
        UIManager.put("ProgressBar.selectionBackground", Color.WHITE);

        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

// Determine the new location of the window
        int w = 522;
        int h = 243;
        int x = (dim.width - w) / 2;
        int y = (dim.height - h) / 2;

        System.out.println(this.getWidth());
        System.out.println(this.getHeight());
        System.out.println(this.getX());
        System.out.println(this.getY());

//        this.setContentPane(new JLabel() {
//
//            BufferedImage img = new Robot().createScreenCapture(new Rectangle(x, y, w, h));
//
//            @Override
//            public void paintComponent(Graphics g) {
//                super.paintComponent(g);
//
//                //sobrescreve o metodo paintComponent para poder tornar o printScreen o fundo do Painel  
//                g.drawImage(img, 0, 0, null);
//            }
//
//        });
        initComponents();
        PainelTrasnparente pt = new PainelTrasnparente(this);
        this.add(pt);
        this.setVisible(false);

        this.repaint();
        this.pack();
        this.setVisible(true);
        timer.start();
        this.getContentPane().setBackground(Color.WHITE);

        // AWTUtilities.setWindowOpacity(this, 0.1F);
//         ProgressPainter painter = new ProgressPainter(Color.WHITE, Color.GREEN);
//                    UIManager.getLookAndFeelDefaults().put("ProgressBar[Enabled+Finished].foregroundPainter", painter);
//                  
//          UIManager.put("ProgressBar.background", Color.BLACK); //colour of the background
//        UIManager.put("ProgressBar.foreground", Color.PINK); //colour of progress bar
//        UIManager.put("ProgressBar.selectionBackground",Color.YELLOW); //colour of percentage counter on black background
//        UIManager.put("ProgressBar.selectionForeground",Color.BLUE); //colour of precentage counter on red background
        //barraProgresso.setValue(20);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        barraProgresso = new javax.swing.JProgressBar();
        jLabel3 = new javax.swing.JLabel();
        img = new javax.swing.JLabel();
        porcentagem = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
        setUndecorated(true);
        setResizable(false);
        setType(java.awt.Window.Type.UTILITY);

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
        jLabel1.setText("BANCO DE QUESTÕES");

        jLabel2.setText("CARREGANDO........");

        barraProgresso.setBackground(new java.awt.Color(51, 102, 255));
        barraProgresso.setForeground(new java.awt.Color(0, 0, 0));
        barraProgresso.setToolTipText("");
        barraProgresso.setBorderPainted(false);
        barraProgresso.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
        barraProgresso.setName(""); // NOI18N
        barraProgresso.setStringPainted(true);
        barraProgresso.setVerifyInputWhenFocusTarget(false);

        jLabel3.setText("Versão: 1.15");

        img.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/hugo/senai/images/spiffygif_32x32.gif"))); // NOI18N

        porcentagem.setText("jLabel4");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(barraProgresso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel3))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(img)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(porcentagem)))
                        .addGap(0, 26, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(porcentagem)))
                    .addComponent(img))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(barraProgresso, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        setSize(new java.awt.Dimension(506, 204));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Metal".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Loading.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Loading.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Loading.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Loading.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new Loading().setVisible(true);
                } catch (AWTException ex) {
                    Logger.getLogger(Loading.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JProgressBar barraProgresso;
    private javax.swing.JLabel img;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel porcentagem;
    // End of variables declaration//GEN-END:variables
}
